package com.stylefeng.symka.modular.system.controller;

import com.stylefeng.symka.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/tag")
public class TagController  extends BaseController {
    /**
     * 跳转到lookup
     */
    @RequestMapping("/lookUp")
    public String lookUp(Model model, String dataUrl, String fields, String fieldsName,String paginationType,boolean muti,String id) {
        String[] fieldArr = StringUtils.delimitedListToStringArray(fields,",");
        String[] fieldNameArr =StringUtils.delimitedListToStringArray(fieldsName,",");
        Assert.isTrue(fieldArr.length==fieldNameArr.length,"参数与参数名长度不一致");
        List<Map<String,String>> fieldList = new ArrayList<>();
        for(int i = 0 ; i < fieldArr.length ;i++){
            Map<String,String> map = new HashMap<>();
            map.put("field",fieldArr[i]);
            map.put("fieldName",fieldNameArr[i]);
            fieldList.add(map);
        }
        model.addAttribute("dataUrl",dataUrl);
        model.addAttribute("fieldList",fieldList);
        model.addAttribute("paginationType",paginationType);
        model.addAttribute("muti",muti);
        model.addAttribute("id",id);

        return "/common/lookup.html";
    }

}
